<style lang="less">
    @import "./main.less";
</style>
<template>
    <div class="main" :class="{'main-hide-text': shrink}">
        <!-- 侧边导航 -->
        <div class="sidebar-menu-con" :style="{width: shrink?'60px':'200px', overflow: shrink ? 'visible' : 'auto'}">
            <shrinkable-menu 
                :shrink="shrink"
                @on-change="handleSubmenuChange"
                :theme="menuTheme" 
                :before-push="beforePush"
                :open-names="openedSubmenuArr"
                :menu-list="menuListChild">               
            </shrinkable-menu>
        </div>
        <div class="main-header-con">
            <div class="main-header">
                <!-- <div class="navicon-con">
                    <Button :style="{transform: 'rotateZ(' + (this.shrink ? '-90' : '0') + 'deg)'}" type="text" @click="toggleClick">
                        <Icon type="navicon" size="32"></Icon>
                    </Button>
                </div> -->
                <!-- logo部分 -->
                <router-link slot="top" class="logo-con" tag="div" to="/home">
                    <img v-show="!shrink"  src="../images/logo.jpg" key="max-logo" class="regular-logo" />
                    <img v-show="shrink" src="../images/logo-min.jpg" key="min-logo" class="small-logo" />
                </router-link>
                <!-- 面包屑 -->
                <div class="header-middle-con">
                    <div class="main-breadcrumb">
                        <breadcrumb-nav :currentPath="currentPath"></breadcrumb-nav>
                    </div>
                </div>
                <!-- 自定义菜单部分 -->
                <div class="mian-top-menu">
                    <topmenu
                    :menu-list="menuList"
                    :open-names="openedSubmenuArr"></topmenu>
                </div>
                
                <div class="header-avator-con">
                    <!-- 全屏缩放 -->
                    <!-- <full-screen v-model="isFullScreen" @on-change="fullscreenChange"></full-screen> -->
                    <!-- 用户锁 -->
                    <lock-screen></lock-screen>
                    <!-- 主题更换 -->
                    <!-- <theme-switch></theme-switch> -->
                    <!-- 语言切换 -->
                    <!-- <change-language></change-language> -->
                    <!-- 用户图标部分 -->
                    <div class="user-dropdown-menu-con">
                        <Row type="flex" justify="end" align="middle" class="user-dropdown-innercon">
                            <Dropdown transfer trigger="click" @on-click="handleClickUserDropdown">
                                <!-- 显示用户名 -->
                                <a href="javascript:void(0)">
                                    <span class="main-user-name">{{ shownLoginName }}</span>
                                    <Icon type="arrow-down-b"></Icon>
                                </a>
                                <!-- 推出登陆 -->
                                <DropdownMenu slot="list">
                                    <DropdownItem name="loginout">{{'安全退出'|l}}</DropdownItem>
                                </DropdownMenu>
                            </Dropdown>
                            <Avatar :src="avatorPath" style="background: #619fe7;margin-left: 10px;"></Avatar>
                        </Row>
                    </div>
                </div>
            </div>
            <!-- 选项卡 -->
            <!-- <div class="tags-con">
                <tags-page-opened :pageTagsList="pageTagsList"></tags-page-opened>
            </div> -->
        </div>
        <div class="single-page-con" :style="{left: shrink?'60px':'200px'}">
            <div class="single-page">
                <keep-alive :include="cachePage">
                    <router-view></router-view>
                </keep-alive>
            </div>
        </div>
    </div>
</template>
<script>
    import shrinkableMenu from './main-components/shrinkable-menu/shrinkable-menu.vue';
    import tagsPageOpened from './main-components/tags-page-opened.vue';
    import breadcrumbNav from './main-components/breadcrumb-nav.vue';
    import fullScreen from './main-components/fullscreen.vue';
    import lockScreen from './main-components/lockscreen/lockscreen.vue';
    import messageTip from './main-components/message-tip.vue';
    import themeSwitch from './main-components/theme-switch/theme-switch.vue';
    import changeLanguage from './main-components/changelanguage.vue';
    import Cookies from 'js-cookie';
    import util from '@/libs/util.js';
    import AppConsts from '@/libs/appconst.js';
    import topmenu from './main-components/shrinkable-menu/components/topMenu.vue';

    export default {
        components: {
            shrinkableMenu,
            tagsPageOpened,
            breadcrumbNav,
            fullScreen,
            lockScreen,
            messageTip,
            themeSwitch,
            changeLanguage,
            topmenu
        },
        data () {
		
            return {
                shrink: false,
                userName: '',
                isFullScreen: false,
                openedSubmenuArr: this.$store.state.app.openedSubmenuArr,
                appConsts:AppConsts,
                menuListChild:[]
            };
        },
        computed: {
            menuList () {
                return this.$store.state.app.menuList;
            },
            
            pageTagsList () {
                return this.$store.state.app.pageOpenedList; 
            },
            currentPath () {
                return this.$store.state.app.currentPath; 
            },
            avatorPath () {
                return localStorage.avatorImgPath;
            },
            cachePage () {
                return this.$store.state.app.cachePage;
            },
            lang () {
                return this.$store.state.app.lang;
            },
            menuTheme () {
                return this.$store.state.app.menuTheme;
            },
            mesCount () {
                return this.$store.state.app.messageCount;
            },
            shownLoginName(){
                let username=this.$store.state.session.user?this.$store.state.session.user.userName:'';
                if(!abp.multiTenancy.isEnabled){
                    return username
                }
                return (this.$store.state.session.tenant?this.$store.state.session.tenant.tenancyName:'.')+ "\\" + username;
            }
        },
        methods: {
            init () {
                let pathArr = util.setCurrentPath(this, this.$route.name);
                this.$store.commit('updateMenulist');
                if (pathArr.length >= 2) {
                    this.$store.commit('addOpenSubmenu', pathArr[1].name);
                }
                this.userName = Cookies.get('user');
                let messageCount = 3;
                this.messageCount = messageCount.toString();
                this.checkTag(this.$route.name);
                this.$store.commit('setMessageCount', 3);
            },
            toggleClick () {
                this.shrink = !this.shrink;
            },
            handleClickUserDropdown (name) {
                if (name === 'loginout') {
                    this.$store.commit('clearOpenedSubmenu');
                    this.$store.commit('user/logout', this);                    
                }
            },
            checkTag (name) {
                let openpageHasTag = this.pageTagsList.some(item => {
                    if (item.name === name) {
                        return true;
                    }
                });

                if (!openpageHasTag) {
                    util.openNewPage(this, name, this.$route.params || {}, this.$route.query || {});
                }
            },
            handleSubmenuChange (val) {
                
            },
            beforePush (name) {
                return true;
            },
            fullscreenChange (isFullScreen) {

            }
        },
        watch: {
            '$route' (to) {
                this.$store.commit('setCurrentPageName', to.name);
                let pathArr = util.setCurrentPath(this, to.name);
                
                if (pathArr.length > 2) {
                    this.$store.commit('addOpenSubmenu', pathArr[1].name);
                }
                this.checkTag(to.name);
                localStorage.currentPageName = to.name;
            },
            lang () {
                util.setCurrentPath(this, this.$route.name); // Used to refresh the breadcrumbs when switching languages
            }
        },
        mounted () {
            this.init();           
            // if(this.$store.state.session.application.features['SignalR']){
            //     if (this.$store.state.session.application.features['SignalR.AspNetCore']) {
            //         SignalRAspNetCoreHelper.initSignalR();
            //     } else {
            //         SignalRHelper.initSignalR();
            //     }
            // }
        },
        created () {
            // Display a list of open pages
            this.$store.commit('setOpenedList');
        }
    };
</script>
<style lang="less" scoped>
.app-main{
    
    .main-header-con{
        // height: 60px;
        // width:100%
        padding-left:0;
        
    }
    .single-page-con{
        // top:60px;
        
    }
    .sidebar-menu-con{
        margin-top:60px;
    }
    .main-header{
        width:100%;
        .logo-con{
            width:200px;
        }
        .header-middle-con{
            left: 200px;
            top:55px;
            overflow: visible;
        }
        .header-avator-con{
            width:200px;
            z-index: 1222;
        }
        .mian-top-menu{
            position: absolute;
            left: 200px;
            top:0;
            overflow: hidden;
            width:100%;
            padding-right:200px;
        }
    }
}
</style>

